package com.kfm.tool;

import com.kfm.control.JdbcSelect;
import com.kfm.map.FileTA;
import com.kfm.map.ServerTA;

import java.util.ArrayList;
import java.util.List;

public class ServerFile {
    /**
     * 获取所要同步的文件
     */
    public static List<String> getFiles() throws Exception {
        String sql = "SELECT * FROM fileta ORDER BY id DESC LIMIT 1  ";
        List<String> list = new ArrayList<>();
        List<FileTA> selectinfo = JdbcSelect.selectinfo(new FileTA(), sql);
        for (FileTA fileTA : selectinfo) {
            list.add(fileTA.getFile_Path());
        }
        return list;
    }
    public static void uplod(String filePath,String fileName) throws Exception {
        String filpathcomplete = filePath+fileName;
        List<ServerTA> result = ServerServlet.getResult();
        for (ServerTA serverTA : result) {
            int resp = ServerServlet.getResponse(serverTA.getUrl());
            if (resp == 200) {
                boolean ftp = ServerServlet.ftp(serverTA, filpathcomplete);
                if (ftp) {
                    JdbcSelect.insertInfoLogs("上传文件" + " " + fileName);
                }
            }
        }
    }
}
